<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>服务对象地址</title>

		<link rel="stylesheet" type="text/css" href="../css/mui.min.css" />
		<link rel="stylesheet" type="text/css" href="../css/own.css" />
		<link rel="stylesheet" type="text/css" href="../css/iconfont.css" />
		<link rel="stylesheet" href="../css/icons-extra.css" />
		<style type="text/css">
			/*下面两项是重置muicss的输入框label和input之间的宽比率*/
			
			.mui-input-row label {
				width: 20%;
			}
			
			.mui-input-row label~input {
				width: 80%;
			}
			
			.name {
				float: left;
			}
			
			.number {
				float: left;
				float: right;
			}
		</style>
	</head>

	<body style="background-color: #FFFFFF;">
		<header class="mui-bar mui-bar-nav" style="background-color: #FFFFFF;">
			<button type="button" class="mui-action-back mui-btn  mui-btn-link mui-pull-left own-button">
			<span class="mui-action-back mui-icon mui-icon-left-nav own-left-nav-color"></span>
			<span class="own-left-nav-color"></span>
		</button>
			<h1 class="mui-title">服务对象地址</h1>
		</header>

		<div class="mui-content" style="background-color: #FFFFFF;">
			<div id="detailsMap">

				<div id="detailsMap-js">

				</div>

			</div>

			<div style="text-align: center; padding-bottom: 30px;">
				<button type="button" class="add-bt" id="add-bt"><span class="mui-icon mui-icon-plus"></span>&nbsp;添加服务对象地址</button>

			</div>

		</div>

		</div>
		<script src="../js/mui.min.js" charset="UTF-8"></script>
		<script src="../js/own.js" charset="UTF-8"></script>
		<script type="text/javascript" src="../js/url.js"></script>

	</body>
	<script>
		mui.plusReady(function() {

			document.getElementById("add-bt").addEventListener('tap', function() {

				mui.openWindow({
					url: 'add-addressList.html',
					id: 'add-addressList.html',

				});
			});
			
			//alert(plus.webview.currentWebview().id);

			window.addEventListener('refresh', function() {
				//alert(555);
				plus.webview.currentWebview().reload();
			});
			
			var data = {};
				data.tokenCode = plus.storage.getItem("tokenCode");
				data.accountId = plus.storage.getItem("accountId");

			mui.ajax(url + 'rest/searchAccount', {

					data: data,

					dataType: 'json', //服务器返回json格式数据

					type: 'POST', //HTTP请求类型

					timeout: 10000, //超时时间设置为10秒；

					//headers:{'Content-Type':'application/json'},	              

					success: function(result) {

						if(result.status != '0') {
							mui.alert("查询地址信息错误");

						} else {

							//document.getElementById("detailsMap").innerHTML=userAddrList;

							//alert(userAddrList);
							var htmlStr = '<ul id="addressList" class="mui-table-view">';

							var obj = result.data.userAddresses;

							for(var i = 0; i < obj.length; i++) {
								//alert(obj[i].name);
								//alert(obj[i].phone);

								htmlStr += ' <li class="mui-table-view-cell">'
								htmlStr += '<h5 class="name" style="color:#000">' + obj[i].name + '</h5>';
								htmlStr += '<h5 class="number" style="color:#000">' + obj[i].phone + '</h5>';
								htmlStr += '<p class="address mui-ellipsis-2" style="clear: both;" >' + obj[i].province + " " + obj[i].city + " " + obj[i].area + " " + '</p>';
								htmlStr += '<p class="orderAddrDetail">' + obj[i].address + '</p>';
								htmlStr += '</li>';

							}
							htmlStr += '</ul>';
							document.getElementById("detailsMap-js").innerHTML = htmlStr;

							/*function blackobj(){
	 					alert(111);
							plus.storage.setItem("orderName",$("#back-name").text());
							plus.storage.setItem("oorderPhone",$("#back-phone").text());
							plus.storage.setItem("orderAddr",$("#back-address").text());
							plus.storage.setItem("orderAddrDetail",$("#back-address").text());
						}*/

							mui(".mui-table-view").on('tap', '.mui-table-view-cell', function() {
								//获取id
								//									  var id = this.getAttribute(plus.storage.setItem("orderName",$("#back-name").text()));
								//									   var id = this.getAttribute(plus.storage.setItem("orderName",$("#back-name").text()));
								//									   var id = this.getAttribute(plus.storage.setItem("orderName",$("#back-name").text()));
								//									   var id = this.getAttribute(plus.storage.setItem("orderName",$("#back-name").text()));
								//alert($(this).html());

								//alert(this.getElementsByClassName("name")[0].innerHTML);
								
								//alert(555);

								plus.storage.setItem("orderName", this.getElementsByClassName("name")[0].innerHTML);
								plus.storage.setItem("orderAddr", this.getElementsByClassName("address")[0].innerHTML);
								plus.storage.setItem("orderPhone", this.getElementsByClassName("number")[0].innerHTML);
								plus.storage.setItem("orderAddrDetail", this.getElementsByClassName("orderAddrDetail")[0].innerHTML);
								mui.back();
//								var ws = plus.webview.currentWebview();
//							plus.webview.close(ws);
//
//							var list = plus.webview.getWebviewById('Home/spirit.html');
//							//触发列表界面的自定义事件（refresh）,
//							//alert(list.id);
//							mui.fire(list, 'refresh');

							})

						}
						},
						error: function(xhr, type, errorThrown) {

							//异常处理；

							mui.alert("查询地址信息异常")

						}
					});

			});

	</script>

</html>